package fr.labri.harmony.analysis.jsep.results;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.StringEscapeUtils;

import au.com.bytecode.opencsv.CSVReader;

public class AnalyzeCategory {

	public static void main(String[] args) throws IOException {
		String file = "libraries_usage.csv";
		CSVReader reader = new CSVReader(new InputStreamReader(new FileInputStream(new File(file))), ',', '"', 1);
		String[] nextLine;

		PrintStream ps = new PrintStream(System.out);
		for(Set<String> cat : LoadRules.getCategories()) {
			if(cat.contains("jmock")==false)
				continue;
			//
			//			List<String> sql = new ArrayList<>(Arrays.asList("mysql", "h2", "hsqldb", "derby", "postgresql", "sqljet", "sqlite-jdbc"));
			//			List<String> nosql = new ArrayList<>(Arrays.asList("cassandra", "leveldb", "db4o", "hbase", "mongo-java-driver", "infinispan", "neo4j", "hazelcast"));
			//
			//			int intra_sql=0;
			//			int intra_nosql=0;
			//			int sql_nosql=0;
			//			int nosql_sql=0;
			//
			//			while ((nextLine = reader.readNext()) != null) {
			//				if (nextLine != null) {
			//					if(nextLine[3].equals("true")==false)
			//						continue;
			//					String source = nextLine[0];
			//					if(cat.contains(source)) {
			//						String target = nextLine[1];
			//						int score = Integer.valueOf(nextLine[2]);
			//						
			//						if(sql.contains(source) && sql.contains(target)) {
			//							intra_sql+= score;
			//						}
			//						else if(sql.contains(source) && nosql.contains(target)) {
			//							sql_nosql+= score;
			//						}
			//						else if(nosql.contains(source) && sql.contains(target)) {
			//							nosql_sql+= score;
			//						}
			//						else if(nosql.contains(source) && nosql.contains(target)) {
			//							intra_nosql+= score;
			//						}
			//					}
			//				}
			//			}
			//			
			//			ps.println("Intra SQL "+intra_sql);
			//			ps.println("Intra NoSQL "+intra_nosql);
			//			ps.println("SQL -> NoSQL "+sql_nosql);
			//			ps.println("NoSQL -> SQL "+nosql_sql);

			while ((nextLine = reader.readNext()) != null) {
				if (nextLine != null) {
					String lib = nextLine[0];
					if(cat.contains(lib)) {
						String in = nextLine[2];
						String out = nextLine[3];
						ps.println(lib+"\t"+in+"\t"+out);
					}
				}
			}
		}
		reader.close();
	}

}
